import time
from data001.Tools.Tools import Tools
from data001.Page.Page1 import Page1
from selenium.webdriver.common.by import By
class Page2(Page1):
    # 点击首页
    ShouYe_loc = (By.LINK_TEXT, '首页')
    def ShouYe(self):
        self.click(self.ShouYe_loc)
    # 输入商品名称
    input1_loc = (By.XPATH, '//*[@id="searchForm"]/div[1]/input')
    def input1(self):
        self.send_keys(self.input1_loc, '蓝牙耳机(旗舰版)')
    # 点击搜索按钮
    button_sousuo_loc = (By.CLASS_NAME, 'search-input-btn')
    def button_sousuo(self):
        self.click(self.button_sousuo_loc)
    # 断言1 进入搜索结果页
    dy1_loc = (By.XPATH, '/html/body/div[4]/a[2]')
    def dy1(self):
        return self.text(self.dy1_loc)
    # 点击搜索商品
    dj_loc = (By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img')
    def dj(self):
        self.click(self.dj_loc)
    # 断言2  进入商品详情页
    dy2_loc = (By.XPATH, '//*[@id="goodsForm"]/div/div[1]/span')
    def dy2(self):
        return self.text(self.dy2_loc)
    # 点击立即购买
    click_goumai_loc = (By.ID, 'buy-cart')
    def click_goumai(self):
        self.click(self.click_goumai_loc)
    # 断言3  进入确认订单页
    dy3_loc = (By.XPATH, '/html/body/div[4]/div[1]/a[2]')
    def dy3(self):
        return self.text(self.dy3_loc)
    # 添加地址
    address_loc = (By.NAME, 'address_id')
    def address(self):
        self.click(self.address_loc)
    # 点击支付方式
    payment_loc = (By.NAME, 'payment')
    def payment(self):
        self.click(self.payment_loc)
    # 点击下一步
    order_button_loc = (By.ID, 'order-button')
    def order_button(self):
        self.click(self.order_button_loc)
    # 点击查看订单
    immediate_loc = (By.CLASS_NAME, 'immediate-pay')
    def immediate(self):
        self.click(self.immediate_loc)

    def test_a3mall_sousuo(self):
        Tools().Log()
        self.test_a3mall_login()
        time.sleep(5)
        self.ShouYe()
        self.input1()
        self.button_sousuo()
        time.sleep(2)
        print('断言1',self.dy1())
        self.dj()
        time.sleep(2)
        print('断言2', self.dy2())
        self.click_goumai()
        time.sleep(2)
        print('断言3', self.dy3())
        self.address()
        self.payment()
        self.order_button()
        self.immediate()
        time.sleep(3)
